package juc.threadcore;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class SleepDontRelleaseLock {
    public static void main(String[] args) {
        Lock lock = new ReentrantLock();
        new Thread(() -> {
            lock.lock();
            try {
                System.out.println("线程" + Thread.currentThread().getName() + "得到了锁");
                Thread.sleep(5000);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                lock.unlock();
                System.out.println("线程" + Thread.currentThread().getName() + "释放了锁");
            }
        }).start();

        new Thread(() -> {
            lock.lock();
            try {
                System.out.println("线程" + Thread.currentThread().getName() + "得到了锁");
                TimeUnit.SECONDS.sleep(2);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                lock.unlock();
                System.out.println("线程" + Thread.currentThread().getName() + "释放了锁");
            }
        }).start();
    }

}
